package com.jz.community.moduleshopping.confirmOrder.presenter;

import android.view.View;

import com.jz.community.basecomm.bean.baseGoods.ShopInfo;
import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.WpToast;
import com.jz.community.moduleshopping.confirmOrder.bean.BaseOrderCouponInfo;
import com.jz.community.moduleshopping.confirmOrder.bean.OrderCouponInfo;
import com.jz.community.moduleshopping.confirmOrder.bean.UpdateOrderCouponInfo;
import com.jz.community.moduleshopping.confirmOrder.bean.OrderPostageInfo;
import com.jz.community.moduleshopping.confirmOrder.bean.SubmitOrderBean;
import com.jz.community.moduleshopping.confirmOrder.bean.SubmitOrderResultBean;
import com.jz.community.moduleshopping.confirmOrder.bean.UpdateCouponInfo;
import com.jz.community.moduleshopping.confirmOrder.model.ConfirmOrderModel;
import com.jz.community.moduleshopping.confirmOrder.model.ConfirmOrderModelImpl;
import com.jz.community.moduleshopping.confirmOrder.ui.NewConfirmOrderView;
import com.jz.community.moduleshopping.goodsDetail.bean.GoodsCouponInfo;

import java.util.List;

public class NewConfirmPresenter extends BaseLifeCyclePresent<NewConfirmOrderView.View> implements NewConfirmOrderView.Presenter {


    private ConfirmOrderModel confirmOrderModel;
    private NewConfirmOrderView.View mView;

    public NewConfirmPresenter(NewConfirmOrderView.View mView) {
        this.mView = mView;
        this.confirmOrderModel = new ConfirmOrderModelImpl(mView.getContext());
    }

    @Override
    public void submitOrder(SubmitOrderBean orderSubmit, View v) {

        confirmOrderModel.submitOrder(orderSubmit, new OnLoadListener<SubmitOrderResultBean>() {
            @Override
            public void onSuccess(SubmitOrderResultBean resultBean) {
                mView.showSubmitOrderResult(resultBean, v);
            }

            @Override
            public void onFail(String s, int code) {
                if (!Preconditions.isNullOrEmpty(s)) {
                    WpToast.l(mView.getContext(), s);
                }
            }
        });
    }

    @Override
    public void orderPostage(SubmitOrderBean orderSubmit) {
        confirmOrderModel.orderPostage(orderSubmit, new OnLoadListener<OrderPostageInfo>() {
            @Override
            public void onSuccess(OrderPostageInfo resultBean) {
                mView.showOrderPostageResult(resultBean);
            }

            @Override
            public void onFail(String s, int code) {
            }
        });
    }

    @Override
    public void getOrderPlatformAndShopCouponInfo(List<UpdateOrderCouponInfo> shopVoList) {
        confirmOrderModel.requestOrderPlatformAndShopCouponInfo(shopVoList, new OnLoadListener<OrderCouponInfo>() {
            @Override
            public void onSuccess(OrderCouponInfo orderCouponInfo) {
                mView.showOrderPlatformAndShopCouponInfo(orderCouponInfo);
            }

            @Override
            public void onFail(String s, int code) {

            }
        });
    }

    @Override
    public void getOrderPlatformCouponInfo(List<UpdateOrderCouponInfo> shopVoList) {
        confirmOrderModel.requestOrderPlatformCouponInfo(shopVoList, new OnLoadListener<List<BaseOrderCouponInfo>>() {
            @Override
            public void onSuccess(List<BaseOrderCouponInfo> orderCouponInfo) {
                mView.showOrderPlatformCouponInfo(orderCouponInfo);
            }

            @Override
            public void onFail(String s, int code) {

            }
        });
    }

    @Override
    public void getUpdateOrderCouponInfo(UpdateCouponInfo updateCouponInfo) {
        confirmOrderModel.requestUpdateOrderCouponInfo(updateCouponInfo, new OnLoadListener<GoodsCouponInfo>() {
            @Override
            public void onSuccess(GoodsCouponInfo orderCouponInfo) {
            }

            @Override
            public void onFail(String s, int code) {

            }
        });
    }

    /**
     * 获取创建订单参数对象
     *
     * @param shopInfo
     * @param consigneeAddress
     * @param consigneeName
     * @param consigneePhone
     * @param couponId
     * @param cityCode
     * @return
     */
    public SubmitOrderBean getCreateConfirmOrderData(ShopInfo shopInfo,String addressId, String consigneeAddress, String consigneeName, String consigneePhone, String couponId, String cityCode, double sendPrice, String mentionId, String mentionName, String mentionPhone) {
        return confirmOrderModel.createConfirmOrderData(shopInfo, addressId,consigneeAddress, consigneeName, consigneePhone, couponId, cityCode, sendPrice, mentionId, mentionName, mentionPhone);
    }

    /**
     * 获取邮费参数对象
     *
     * @param shopInfo
     * @param consigneeAddress
     * @param consigneeName
     * @param consigneePhone
     * @param couponId
     * @param cityCode
     * @param sendPrice
     * @param mentionId
     * @param mentionName
     * @param mentionPhone
     * @return
     */
    public SubmitOrderBean getCreateConfirmOrderPostageData(ShopInfo shopInfo, String addressId,String consigneeAddress, String consigneeName, String consigneePhone, String couponId, String cityCode, double sendPrice, String mentionId, String mentionName, String mentionPhone) {
        return confirmOrderModel.createConfirmOrderData(shopInfo, addressId,consigneeAddress, consigneeName, consigneePhone, couponId, cityCode, sendPrice, mentionId, mentionName, mentionPhone);
    }

    /**
     * 获取平台、商家优惠券参数
     *
     * @param shopInfo
     * @return
     */
    public List<UpdateOrderCouponInfo> getOrderPlatformAndShopCouponParam(ShopInfo shopInfo) {
        return confirmOrderModel.orderPlatformAndShopCouponParam(shopInfo);
    }

    /**
     * 获取平台优惠券参数
     *
     * @param shopInfo
     * @return
     */
    public List<UpdateOrderCouponInfo> getOrderPlatformCouponParam(ShopInfo shopInfo) {
        return confirmOrderModel.orderPlatformCouponParam(shopInfo);
    }
}
